<load target="js/document_admin.js" usecdn="true" />
<!--%import("filter/insert_extra_var.xml")-->
<!--%import("filter/delete_extra_var.xml")-->

<block cond="$selected_var_idx && $extra_keys[$selected_var_idx]">
    {@ $selected_var = $extra_keys[$selected_var_idx] }
</block>
<div cond="$XE_VALIDATOR_MESSAGE && $XE_VALIDATOR_ID == 'modules/document/tpl/extra_keys/1'" class="message {$XE_VALIDATOR_MESSAGE_TYPE}">
	<p>{$XE_VALIDATOR_MESSAGE}</p>
</div>

<!--@if($type == 'insertExtraForm' || $selected_var_idx)-->
	<section class="section">
		<h1>{$lang->extra_vars}</h1>
		<form ruleset="insertExtraVar" action="./" method="post" class="x_form-horizontal">
			<input type="hidden" name="module" value="document" />
			<input type="hidden" name="act" value="procDocumentAdminInsertExtraVar" />
			<input type="hidden" name="module_srl" value="{$module_srl}" />
			<input type="hidden" name="var_idx" value="{$selected_var_idx}" />
			<input type="hidden" name="success_return_url" value="{getUrl('type', '')}" />
			<input type="hidden" name="xe_validator_id" value="modules/document/tpl/extra_keys/1" />

			<div class="x_control-group">
				<label class="x_control-label" for="eid">{$lang->eid}</label>
				<div class="x_controls">
					<input type="text" name="eid" id="eid" value="{$selected_var->eid}" placeholder="Ex) extra_vars_1" />
					<p class="x_help-inline">{$lang->about_extra_vars_eid_value}</p>
				</div>
			</div>
			<div class="x_control-group">
				<label class="x_control-label" for="lang_name">{$lang->column_name}</label>
				<div class="x_controls">
					<input type="text" name="name" id="name" value="<!--@if(strpos($selected_var->name, '$user_lang->') === false)-->{$selected_var->name}<!--@else-->{htmlspecialchars($selected_var->name)}<!--@end-->" class="lang_code" placeholder="Ex) Your favorite color." />
				</div>
			</div>
			<div class="x_control-group">
				<label class="x_control-label" for="type">{$lang->column_type}</label>
				<div class="x_controls">
					<select name="type" id="type">
						<option loop="$lang->column_type_list => $k, $v" value="{$k}" selected="selected"|cond="$selected_var->type == $k">{$lang->column_type_list[$k]}</option>
					</select>
				</div>
			</div>
			<div class="x_control-group">
				<label class="x_control-label">{$lang->is_required}</label>
				<div class="x_controls">
					<label class="x_inline" for="is_required_y"><input type="radio" name="is_required" id="is_required_y" value="Y" checked="checked"|cond="$selected_var->is_required == 'Y'" /> {$lang->yes}</label>
					<label class="x_inline" for="is_required_n"><input type="radio" name="is_required" id="is_required_n" value="N" checked="checked"|cond="$selected_var->is_required != 'Y'" /> {$lang->not}</label>
				</div>
			</div>
			<div class="x_control-group">
				<label class="x_control-label" for="default">{$lang->default_value}</label>
				<div class="x_controls">
					<input type="text" name="default" id="default" value="{$selected_var->default}" placeholder="Ex) Red, Green, Blue" />
					<p class="x_help-inline">{$lang->about_extra_vars_default_value}</p>
				</div>
			</div>
			<div class="x_control-group">
				<label class="x_control-label" for="lang_desc">{$lang->description}</label>
				<div class="x_controls">
					<input type="text" name="desc" id="desc" value="{$selected_var->desc}" class="lang_code" placeholder="Ex) Displayed as your choice." />
				</div>
			</div>
			<div class="x_control-group">
				<label class="x_control-label">{$lang->cmd_search}</label>
				<div class="x_controls">
					<label class="x_inline" for="search_y"><input type="radio" name="search" id="search_y" value="Y" checked="checked"|cond="$selected_var->search=='Y'" /> {$lang->yes}</label>
					<label class="x_inline" for="search_n"><input type="radio" name="search" id="search_n" value="N" checked="checked"|cond="$selected_var->search!='Y'" /> {$lang->not}</label>
				</div>
			</div>

			<div class="x_clearfix btnArea">
				<div class="x_pull-left">
					<a class="x_btn" href="{getUrl('type','','selected_var_idx','')}">{$lang->cmd_back}</a>
				</div>
				<div class="x_pull-right">
					<!--@if($selected_var)-->
					<button type="submit" class="x_btn x_btn-primary">{$lang->cmd_modify}</button>
					<!--@else-->
					<button type="submit" class="x_btn x_btn-primary">{$lang->cmd_insert}</button>
					<!--@end-->
				</div>
			</div>
		</form>
	</section>

<!--@else-->

<section class="section">
	<div class="x_clearfix">
		<div class="x_btn-group x_pull-right">
			<a class="x_btn" href="{getUrl('type','insertExtraForm','selected_var_idx','')}">{$lang->cmd_insert}</a>
		</div>
	</div>
	<table class="x_table x_table-striped x_table-hover">
		<thead>
			<tr class="nowr">
				<th>{$lang->no}</th>
				<th>{$lang->eid}</th>
				<th>{$lang->column_name}</th>
				<th>{$lang->column_type}</th>
				<th>{$lang->default_value}</th>
				<th>{$lang->is_required}</th>
				<th>{$lang->cmd_search}</th>
				<th>&nbsp;</th>
			</tr>
		</thead>
		<tbody>
			<block loop="$extra_keys => $key,$val">
			<tr>
				<td rowspan="2"|cond="$val->desc">{$val->idx}</td>
				<td>{$val->eid}</td>
				<td class="nowr"><strong>{$val->name}</strong></td>
				<td class="nowr">{$lang->column_type_list[$val->type]}</td>
				<td>{$val->default}&nbsp;</td>
				<td class="nowr"><!--@if($val->is_required=='Y')--><strong>Y</strong><!--@else-->N<!--@end--></td>
				<td class="nowr"><!--@if($val->search=='Y')--><strong>Y</strong><!--@else-->N<!--@end--></td>
				<td class="nowr" style="text-align:right">
					<block cond="$val->idx > 1">
						<button type="button" class="x_icon-arrow-up" onclick="moveVar('up','{$module_srl}','{$val->idx}')">{$lang->cmd_move_up}</button>
					</block>
					<block cond="count($extra_keys) > $val->idx">
						<button type="button" class="x_icon-arrow-down" onclick="moveVar('down','{$module_srl}','{$val->idx}')">{$lang->cmd_move_down}</button>
					</block>
					<a href="{getUrl('selected_var_idx',$val->idx)}" class="x_icon-wrench">{$lang->cmd_modify}</a>
					<button type="button" class="x_icon-trash" onclick="return doDeleteExtraKey('{$module_srl}','{$val->idx}');">{$lang->cmd_delete}</button>
				</td>
			</tr>
			<tr cond="$val->desc">
				<td colspan="7">{$val->desc}</td>
			</tr>
			</block>
		</tbody>
	</table>
	<div class="x_clearfix">
		<div class="x_pull-right">
			<a class="x_btn" href="{getUrl('type','insertExtraForm','selected_var_idx','')}">{$lang->cmd_insert}</a>
		</div>
	</div>
</section>
<!--@end-->

<form id="fo_delete" name="fo_delete" method="post" action="./">
<input type="hidden" name="module_srl" value="" />
<input type="hidden" name="var_idx" value="" />
</form>
